package de.tiemannjan.android.util;

import android.location.Location;

public class LocationTracker {
	private Location mLocationTmp;
	private float mDistance; // distance in meters
	private boolean mRunning;
	
	private final int METERS_PER_KM = 1000;
	
	public LocationTracker(){
		mDistance = 0.0f;
		mRunning = false;
	}
	
	public void addLocation(Location location){
		// TODO: Is this calculation method accurate enough?  Do I need to consider the altitude separately?
		if (mLocationTmp != null && getRunning()){
			mDistance += mLocationTmp.distanceTo(location);
		}
		// TODO: save each location in a SQLite database for later export
		// TODO: check for case that location equals null
		mLocationTmp = location;
	}
	
	public float getDistance(){
		return mDistance;
	}
	
	public double getDistanceKm(){
		return (double) getDistance() / (double) this.METERS_PER_KM;
	}
	
	public void start(){
		mRunning = true;
	}
	
	public void stop(){
		mRunning = false;
	}
	
	private boolean getRunning(){
		return mRunning;
	} 
}
